//
//  LBPageSingleController.m
//  TEXT
//
//  Created by mac on 2024/8/11.
//  Copyright © 2024 刘博. All rights reserved.
//

#import "LBPageSingleController.h"
#import "LBPageSmoothView.h"
#import "LBFunctionTestHeader.h"
#import "LLLCollectionView.h"

@interface LBPageSingleController () <LBPageSmoothListViewDelegate,UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation LBPageSingleController

- (instancetype)init
{
    if (self = [super init]) {
        [self.collectionView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.collectionView];
    // Do any additional setup after loading the view.
}

- (void)dealloc
{
    [self.collectionView removeObserver:self forKeyPath:@"contentOffset"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"contentOffset"]) {
        if (self.collectionView.contentOffset.y == -340) {
            
        }
    }
}

#pragma mark - lazy load

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kkk" forIndexPath:indexPath];
    UIView *view = [cell.contentView viewWithTag:1000];
    [view removeFromSuperview];
    cell.largeContentTitle = [NSString stringWithFormat:@"%ld",indexPath.item];
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 40)];
    title.text = [NSString stringWithFormat:@"%ld", indexPath.item];
    title.tag = 1000;
    [cell.contentView addSubview:title];
    cell.contentView.backgroundColor = [UIColor yellowColor];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 100;
}

- (UIView *)listView
{
    return self.view;
}

- (UIScrollView *)listScrollView
{
    return self.collectionView;
}

#pragma mark - lazy load

- (LLLCollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(SCREEN_WIDTH, 100);
        _collectionView = [[LLLCollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 40) collectionViewLayout:layout];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"kkk"];
    }
    return _collectionView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
